package hot100;

public class Solution100 {
    boolean isSame = true;
    public boolean isSameTree(TreeNode p, TreeNode q) {
        dfs(p, q);
        return isSame;
    }

    private void dfs(TreeNode root1, TreeNode root2) {
        if (root1 == null && root2 == null) {
            return;
        }
        if (root1 == null || root2 == null) {
            isSame = false;
            return;
        }
        dfs(root1.left, root2.left);
        if (root1.val != root2.val) {
            isSame = false;
        }
        dfs(root1.right, root2.right);
    }
}
